/**
 * BatchRunAction.java - 2012-6-6
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * Project Info: China UnionPay Internet Acquiring Project
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *   wanghulin        2012-6-6       
 * =============================================================================
 */
package com.lijin.batchsys.web.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.lijin.batchsys.framework.common.BatchUtil;
import com.lijin.batchsys.framework.control.BatchControl;
import com.lijin.batchsys.framework.enums.RunningMode;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author wanghulin
 *
 */
public class BatchRunAction extends ActionSupport {
	
	private static final long serialVersionUID = -4144567455126510340L;


	/**
	 * 通过batchNo获得对应的jobList
	 * @return
	 */
	public String runJob() {
		HttpServletRequest request = ServletActionContext.getRequest();
		int batchNo = Integer.parseInt(request.getParameter("batchNo"));
		int jobNo = Integer.parseInt(request.getParameter("jobNo"));
		String batchDateStr = request.getParameter("batchTime");
		if(batchDateStr.equals("")) batchDateStr = BatchUtil.preDay(new Date());
		
		try{
		  BatchControl.startBatch(RunningMode.START_SINGLE_JOB, batchDateStr, batchNo, jobNo, 0); 
	    }catch (Exception e) {
		   return "error";
	    }
		return "runJobResult";
	}
	
	/**
	 * 通过batchNo获得对应的jobList
	 * @return
	 */
	public String runStep() {
		HttpServletRequest request = ServletActionContext.getRequest();
		int batchNo = Integer.parseInt(request.getParameter("batchNo"));
		int jobNo = Integer.parseInt(request.getParameter("jobNo"));
		int stepNo = Integer.parseInt(request.getParameter("stepNo"));
		
		String batchDateStr = request.getParameter("batchTime");
		if(batchDateStr.equals("")) batchDateStr = BatchUtil.preDay(new Date());
		
		try{
			BatchControl.startBatch(RunningMode.START_SINGLE_STEP, batchDateStr, batchNo, jobNo, stepNo); 
		}catch (Exception e) {
			return "error";
		}
		
		
		return "runStepResult";
	}

}
